home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / jst_dev / sources / OSEmu / lowlevel.s < prev    next >
Text File  |  2000-04-12  |  9KB  |  434 lines

  1. * $Id: lowlevel.s 1.1 1999/02/03 04:08:28 jotd Exp $
  2.  
  3.     IFD    HARRY
  4. TEST_JOY_BUTTON:MACRO
  5.     bclr    #JPB_BUTTON_\1,D0    ; button released
  6.     tst.l    D2
  7.     bne.b    .rts_\1
  8.     bset    #JPB_BUTTON_\1,D0    ; button pressed
  9. .rts_\1
  10.     ENDM
  11.     ELSE
  12. TEST_JOY_BUTTON:MACRO
  13.     bclr    #JPB_BUTTON_\1,D0    ; button released
  14.     tst.l    D2
  15.     bne.b    .rts\@
  16.     bset    #JPB_BUTTON_\1,D0    ; button pressed
  17. .rts\@
  18.     ENDM
  19.     ENDC
  20.  
  21. **************************************************************************
  22. *   LOWLEVEL-LIBRARY                                                    *
  23. **************************************************************************
  24. **************************************************************************
  25. *   INITIALIZATION                                                       *
  26. **************************************************************************
  27.  
  28. LOWLINIT    move.l    _lowlbase,d0
  29.         beq    .init
  30.         rts
  31.  
  32. .init        move.l    #162,d0        ; reserved function
  33.         move.l    #80,d1        ; 20 variables: should be OK
  34.         lea    _lowlname,a0
  35.         bsr    _InitLibrary
  36.         move.l    d0,a0
  37.         move.l    d0,_lowlbase
  38.         
  39.         patch    _LVOReadJoyPort(a0),READJOYPORT(pc)
  40.         patch    _LVOSetJoyPortAttrsA(a0),SETJOYPORTATTRS(pc)
  41.         patch    _LVOAddVBlankInt(a0),ADDVBLANKINT(pc)
  42.         patch    _LVOAddKBInt(a0),ADDKBINT(pc)
  43.         patch    _LVOAddTimerInt(a0),ADDTIMERINT(pc)
  44.         patch    _LVORemVBlankInt(a0),MYRTS(pc)
  45.         patch    _LVORemKBInt(a0),MYRTS(pc)
  46.         patch    _LVOSystemControlA(a0),MYRTZ(pc)
  47.         patch    _LVOGetLanguageSelection(a0),GETLANGSEL(pc)
  48.         rts
  49.  
  50. GETLANGSEL:
  51.     moveq.l    #2,D0    ; british english
  52.     rts
  53.  
  54. ; adds a vblank interrupt
  55. ; < A0: intRoutine
  56. ; < A1: intData
  57.  
  58. ADDVBLANKINT:
  59.     movem.l    D2-D7/A2-A6,-(A7)
  60.     lea    .int_entry(pc),A3
  61.     move.l    A0,(A3)
  62.     lea    .caller_int(pc),A0
  63.  
  64.     lea    .int_struct(pc),A3
  65.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  66.     move.b    #0,9(A3)        ; Highest priority
  67.     move.l    .vbname,10(A3)        ; The name of the server (for monitor programs)
  68.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  69.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  70.     move.l    #INTB_VERTB,D0        ; Vertical Blank interrupt
  71.     move.l    $4.W,A6
  72.     move.l    A3,A1            ; pointer on interrupt structure
  73.     JSR    _LVOAddIntServer(A6)    ; Adds the handler to the existing chain
  74.     
  75.     movem.l    (A7)+,D2-D7/A2-A6
  76.  
  77.     moveq.l    #1,D0            ; returns !=0 because success
  78.     rts
  79.  
  80. .caller_int:
  81.     move.l    .int_entry(pc),A5    ; as required in lowlevel autodoc
  82.     jmp    (A5)
  83.  
  84. .int_entry:
  85.     dc.l    0
  86. .int_struct:
  87.     ds.b    22
  88. .vbname:    
  89.     dc.b    "lowlevel vbl",0
  90.     cnop    0,4
  91.  
  92. ; adds a keyboard interrupt
  93. ; < A0: intRoutine
  94. ; < A1: intData
  95.  
  96. ADDKBINT:
  97.     movem.l    D2-D7/A2-A6,-(A7)
  98.     lea    .int_entry(pc),A3
  99.     move.l    A0,(A3)
  100.     lea    .caller_int(pc),A0
  101.  
  102.     lea    .int_struct(pc),A3
  103.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  104.     move.b    #0,9(A3)        ; Highest priority
  105.     move.l    .vbname,10(A3)        ; The name of the server (for monitor programs)
  106.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  107.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  108.     move.l    #INTB_PORTS,D0        ; Ports interrupt
  109.     move.l    $4.W,A6
  110.     move.l    A3,A1            ; pointer on interrupt structure
  111.     JSR    _LVOAddIntServer(A6)    ; Adds the handler to the existing chain
  112.     
  113.     movem.l    (A7)+,D2-D7/A2-A6
  114.     moveq.l    #1,D0            ; returns !=0 because success
  115.     rts
  116.  
  117. .caller_int:
  118.     move.l    .int_entry(pc),A5    ; as required in lowlevel autodoc
  119.     move.b    $BFEC01,D0
  120.     not.b    D0
  121.     ror.b    #1,D0            ; raw keycode
  122.     jmp    (A5)
  123.  
  124. .int_entry:
  125.     dc.l    0
  126. .int_struct:
  127.     ds.b    22
  128. .vbname:    
  129.     dc.b    "lowlevel kb",0
  130.     cnop    0,4
  131.  
  132. ; adds a timer interrupt
  133. ; < A0: intRoutine
  134. ; < A1: intData
  135.  
  136. CIA_TIME_SLICE = 46911
  137.  
  138. ADDTIMERINT:
  139.     movem.l    D2-D7/A2-A6,-(A7)
  140.  
  141.     ; just stores the values
  142.  
  143.     move.l    A0,cia_int_entry
  144.     move.l    A1,cia_int_data
  145.  
  146.     move.l    $4.W,A6
  147.     lea    _ciaaname,A1
  148.     JSR    _LVOOpenResource
  149.     move.l    D0,cia_resource_handler        ; resource handler
  150.  
  151.     lea    cia_caller_int(pc),A0
  152.  
  153.     lea    cia_int_struct(pc),A3
  154.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  155.     move.b    #127,9(A3)        ; Lowest priority
  156.     move.l    cia_int_name,10(A3)        ; The name of the server (for monitor programs)
  157.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  158.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  159.     move.l    #3,D0        
  160.  
  161.     move.l    cia_int_struct(pc),D0    ; only 1 interrupt of this kind
  162.     movem.l    (A7)+,D2-D7/A2-A6
  163.     rts
  164.  
  165. ; A1 <: intHandle (also interrupt structure, hack!)
  166. ; D0 <: time interval (in microseconds)
  167. ; D1 <: continuous (0: one shot)
  168.  
  169. STARTTIMERINT:
  170.     movem.l    D2-D7/A2-A6,-(A7)
  171.  
  172.     move.l    d0,cia_time_interval
  173.  
  174.     move.l    cia_resource_handler,A6
  175.     move.l    #3,D0    
  176.     JSR    _LVOAddICRVector(A6)    ; Adds the handler to the existing chain
  177.     
  178.     movem.l    (A7)+,D2-D7/A2-A6
  179.     rts
  180.  
  181. ; <A1: intHandle
  182.  
  183. STOPTIMERINT:
  184.     movem.l    D2-D7/A2-A6,-(A7)
  185.  
  186.     moveq.l    #3,D0
  187.     move.l    cia_resource_handler,A6
  188.     JSR    _LVORemICRVector(A6)    ; Removes the handler to the existing chain
  189.     
  190.     movem.l    (A7)+,D2-D7/A2-A6
  191.     rts
  192.  
  193. ; routine called by ICRVector
  194.  
  195. cia_caller_int:
  196.     ; time counter, to avoid calling user routine every time
  197.     ; we must check the frequence he requested
  198.  
  199.     ;;to be continued
  200.     ;
  201.  
  202.     move.l    cia_int_entry(pc),A5    ; as required in lowlevel autodoc
  203.     move.l    cia_int_data(pc),A1    ; as required in lowlevel autodoc
  204.     jmp    (A5)
  205.  
  206. cia_resource_handler:
  207.     dc.l    0
  208. cia_time_interval:
  209.     dc.l    0
  210.  
  211. cia_int_struct:
  212.     ds.b    22
  213. cia_int_name:    
  214.     dc.b    "lowlevel timer",0
  215.     cnop    0,4
  216. cia_int_entry:
  217.     dc.l    0
  218. cia_int_data:
  219.     dc.l    0
  220.  
  221.  
  222. ; forces a port to a controller type and allows to reset it
  223.  
  224. SETJOYPORTATTRS:
  225.     moveq.l    #-1,D0    ; all went OK
  226.     rts
  227.  
  228. ; reads joypads
  229.  
  230. READJOYPORT:
  231.     cmp.w    #0,D0
  232.     beq    .joy0
  233.     cmp.w    #1,D0
  234.     beq    .joy1
  235.  
  236.     move.l    #JP_TYPE_NOTAVAIL,D0
  237.     rts
  238. .joy0
  239.     move.l    #JP_TYPE_GAMECTLR,D0    ; joypad connected
  240.  
  241.     btst    #6,$bfe001
  242.     bne    .nob1_0
  243.  
  244.     bset    #JPB_BUTTON_RED,D0    ; fire/lmb
  245.     
  246. .nob1_0:
  247.  
  248.     btst    #6,potinp+$DFF000
  249.     bne    .nob2_0
  250.  
  251.     bset    #JPB_BUTTON_BLUE,D0    ; fire 2/rmb
  252.     move.w    #$CC01,potgo+$DFF000    ; reset ports
  253. .nob2_0    
  254.     ; joystick moves
  255.  
  256.     lea    (joy0dat+_custom),A6
  257.     bsr    .joy_test
  258.  
  259.     rts
  260.  
  261. .joy1
  262.     move.l    #JP_TYPE_GAMECTLR,D0    ; joypad connected
  263.  
  264.     btst    #7,$bfe001
  265.     bne    .nob1_1
  266.  
  267.     bset    #JPB_BUTTON_RED,D0    ; fire/lmb
  268.     
  269. .nob1_1:
  270.  
  271. ;    btst    #14,potinp+$DFF000    ; was wrong ?
  272.     btst    #6,potinp+$DFF000
  273.     bne    .nob2_1
  274.  
  275.     bset    #JPB_BUTTON_BLUE,D0    ; fire 2/rmb
  276.     move.w    #$CC01,(potgo+_custom)    ; reset ports
  277. .nob2_1:
  278.  
  279.     ; joystick moves
  280.  
  281.     lea    (joy1dat+_custom),A6
  282.     bsr    .joy_test
  283.     move.l    D0,-(A7)
  284.     movem.l    D1/D2,-(A7)
  285.     move.l    old_buttonmask,D0
  286.     bsr    .button_test
  287.     movem.l    (A7)+,D1/D2
  288.     move.l    D0,old_buttonmask
  289.     or.l    (A7),D0
  290.     move.l    D0,(A7)
  291.     move.l    (A7)+,D0
  292.     rts
  293.  
  294. ; other joypad buttons by keyboard emulation
  295. ; even a real joypad does not work properly on a real amiga!
  296. ; (I don't really know why!)
  297.  
  298.  
  299. .button_test:
  300.     move.b    KBDVAL,D1
  301.  
  302.     ; press/release
  303.  
  304.     moveq.l    #0,D2
  305.     bclr    #7,D1
  306.     beq.b    .pressed
  307.     moveq.l    #1,D2
  308. .pressed
  309.  
  310.     cmp.b    #$50,D1        ; F1: Blue
  311.     bne    .noblue
  312.     TEST_JOY_BUTTON    BLUE    ; fire 2/blue/rmb
  313.     rts
  314. .noblue
  315.     cmp.b    #$51,D1        ; F2: Green
  316.     bne    .nogreen
  317.     TEST_JOY_BUTTON    GREEN
  318.     rts
  319. .nogreen:
  320.     cmp.b    #$52,D1        ; F3: Yellow
  321.     bne    .noyellow
  322.     TEST_JOY_BUTTON    YELLOW
  323.     rts
  324. .noyellow:
  325.     cmp.b    #$53,D1        ; F4: Play/pause
  326.     bne    .noplay
  327.     TEST_JOY_BUTTON    PLAY
  328.     rts
  329. .noplay:
  330.     cmp.b    #$54,D1        ; F5: left ear
  331.     bne    .nolear
  332.     TEST_JOY_BUTTON    REVERSE
  333.     rts
  334. .nolear:
  335.     cmp.b    #$55,D1        ; F6: right ear
  336.     bne    .norear
  337.     TEST_JOY_BUTTON    FORWARD
  338. .norear:
  339.     rts
  340.  
  341. ; tests joystick moves
  342. ; < A6: custom reg. of the selected joystick
  343. ; > D0: joystick bits set
  344.  
  345. .joy_test:
  346.     movem.l    D4-D6,-(A7)
  347.  
  348.     move.w    (A6),D4
  349.     move.w    D4,D5
  350.     btst    #1,D4
  351.     beq.b    .left_off
  352.     bset    #JPB_JOY_RIGHT,D0
  353.     bra.b    .vert_test
  354. .left_off:
  355.     btst    #9,D4
  356.     beq.b    .vert_test
  357.     bset    #JPB_JOY_LEFT,D0
  358. .vert_test
  359.     lsr.w    #1,D4
  360.     eor.w    D5,D4
  361.     btst    #0,D4
  362.     beq.b    .back_off
  363.     bset    #JPB_JOY_DOWN,D0
  364.     bra.b    .exit
  365. .back_off
  366.     btst    #8,D4
  367.     beq.b    .exit
  368.     bset    #JPB_JOY_UP,D0
  369. .exit
  370.  
  371.     movem.l    (A7)+,D4-D6
  372.     rts
  373.  
  374. old_buttonmask:
  375.     dc.l    0
  376.  
  377.  
  378. LAB_00D7:
  379.     MOVEM.L    D2/A4-A6,-(A7)        ;16A8: 48E7200E
  380.     MOVEA.L    A1,A4            ;16AC: 2849
  381.     MOVEQ    #0,D2            ;16AE: 7400
  382.     MOVE.B    $BFEC01,D2        ;16B0: 143900BFEC01
  383.     NOT.B    D2            ;16B6: 4602
  384.     ROR.B    #1,D2            ;16B8: E21A
  385.     MOVEA.L    (72,A4),A0        ;16BA: 206C0048
  386.     MOVEA.L    (14,A0),A1        ;16BE: 2268000E
  387.     MOVEA.L    (18,A0),A5        ;16C2: 2A680012
  388.     JSR    (A5)            ;16C6: 4E95
  389.     CMP    #$0078,D2        ;16C8: B47C0078
  390.     BEQ.S    LAB_00DD        ;16CC: 6760
  391.     MOVE    D2,D1            ;16CE: 3202
  392.     AND    #$0078,D1        ;16D0: C27C0078
  393.     CMP    #$0060,D1        ;16D4: B27C0060
  394.     BNE.S    LAB_00D8        ;16D8: 6612
  395.     MOVE    (40,A4),D0        ;16DA: 302C0028
  396.     MOVE    D2,D1            ;16DE: 3202
  397.     AND    #$0007,D1        ;16E0: C27C0007
  398.     BCHG    D1,D0            ;16E4: 0340
  399.     MOVE    D0,(40,A4)        ;16E6: 39